package com.stud.validation;

import com.stud.exception.ValidationException;
import com.stud.repository.ClientRepository;
import com.stud.rmi.Client;

import static com.stud.util.StringHelper.isEmpty;

public class ValidatorImpl implements Validator {

    private final ClientRepository clientRepository;

    public ValidatorImpl(ClientRepository clientRepository) {
        this.clientRepository = clientRepository;
    }

    @Override
    public void validate(Client client) throws ValidationException {
        if (isEmpty(client.getFirstName()) || isEmpty(client.getLastName())) {
            throw new ValidationException("Fields can not be empty!");
        }
        if (clientRepository.getClient(client) == null) {
            throw new ValidationException("Can not delete. Client does not exist!");
        }
    }
}
